package com.ruoyi.question.service.impl;

import com.ruoyi.question.domain.DtAnswer;
import com.ruoyi.question.domain.DtQuestion;
import com.ruoyi.question.mapper.DtQuestionMapper;
import com.ruoyi.question.service.IDtCategoryService;
import com.ruoyi.question.service.IDtQuestionAnalysisService;
import com.ruoyi.question.service.IDtQuestionService;
import com.ruoyi.question.service.IDtQuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 题库Service业务层处理
 *
 * @author llc
 * @date 2025-01-06
 */
@Service
public class DtQuestionServiceImpl implements IDtQuestionService {
    @Autowired
    private DtQuestionMapper dtQuestionMapper;
    @Autowired
    private DtAnswerServiceImpl dtAnswerService;
    @Autowired
    private IDtQuestionAnalysisService dtQuestionAnalysisService;
    @Autowired
    private IDtCategoryService dtCategoryService;
    @Autowired
    private IDtQuestionTypeService dtQuestionTypeService;

    /**
     * 查询题库
     *
     * @param id 题库主键
     * @return 题库
     */
    @Override
    public DtQuestion selectDtQuestionById(Long id) {
        DtQuestion dtQuestion = dtQuestionMapper.selectDtQuestionById(id);
        DtAnswer dtAnswer = new DtAnswer();
        dtAnswer.setQuestionId(id);
        List<DtAnswer> dtAnswers = dtAnswerService.selectDtAnswerList(dtAnswer);
        dtQuestion.setDtAnswers(dtAnswers);
        return dtQuestion;
    }

    /**
     * 查询题库列表
     *
     * @param dtQuestion 题库
     * @return 题库
     */
    @Override
    public List<DtQuestion> selectDtQuestionList(DtQuestion dtQuestion) {
        List<DtQuestion> list = dtQuestionMapper.selectDtQuestionList(dtQuestion);
        for (DtQuestion dtQuestion1 : list) {
            DtAnswer dtAnswer = new DtAnswer();
            dtAnswer.setQuestionId(dtQuestion1.getId());
            List<DtAnswer> dtAnswers = dtAnswerService.selectDtAnswerList(dtAnswer);
            dtQuestion1.setDtAnswers(dtAnswers);
        }
        return list;
    }

    /**
     * 新增题库
     *
     * @param dtQuestion 题库
     * @return 结果
     */
    @Override
    public int insertDtQuestion(DtQuestion dtQuestion) {

        return dtQuestionMapper.insertDtQuestion(dtQuestion);
    }

    /**
     * 修改题库
     *
     * @param dtQuestion 题库
     * @return 结果
     */
    @Override
    public int updateDtQuestion(DtQuestion dtQuestion) {
        return dtQuestionMapper.updateDtQuestion(dtQuestion);
    }

    /**
     * 批量删除题库
     *
     * @param ids 需要删除的题库主键
     * @return 结果
     */
    @Override
    public int deleteDtQuestionByIds(Long[] ids) {
        return dtQuestionMapper.deleteDtQuestionByIds(ids);
    }

    /**
     * 删除题库信息
     *
     * @param id 题库主键
     * @return 结果
     */
    @Override
    public int deleteDtQuestionById(Long id) {

        return dtQuestionMapper.deleteDtQuestionById(id);
    }

//    随机获取题库

}
